<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <p>总价格：{{getTotalPrice()}}</p>
        <p>总价格：{{getTotalPrice()}}</p>
        <p>总价格：{{getTotalPrice()}}</p>
        <p>总价格：{{getTotalPrice()}}</p>
    </div>
    <script src="../vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                carts: [
                    { name: 'iphone 13', price: 5000, num: 2 },
                    { name: 'mac book pro', price: 14999, num: 5 }
                ]
            },
            methods: {
                getTotalPrice() {
                    console.log('fn');
                    let n = 0;
                    for (let i = 0; i < this.carts.length; i++) {
                        n += this.carts[i].price * this.carts[i].num;
                    }
                    return n
                }
            }
        })
    </script>
</body>

</html>